import numpy
import matrix


a11 = 2
a12 = 1
a13 = 2
a21 = 4
a22 = 5
a23 = 4
a31 = 6
a32 = -3
a33 = 5

A_33 = [[a11, a12, a13],
        [a21, a22, a23],
        [a31, a32, a33]]


#【Doolittle分解法】
# L是单位下三角阵，U是上三角阵
i = 0
for i in range(3):
    print("原矩阵为：", A_33[i])
    i = i + 1
    
# 分解部分
u11 = a11       # 1行*1列
l21 = a21/u11   # 2行*1列
l31 = a31/u11   # 3行*1列

u12 = a12       # 1行*2列
u22 = a22-(l21*u12)   # 2行*2列
l32 = (a32-l31*u12)/u22   # 3行*2列

u13 = a13       # 1行*3列
u23 = a23-(l21*u13)   # 2行*3列
u33 = a33-(l31*u13)-(l32*u23)   # 3行*3列

L_33 = [[1, 0, 0],
        [l21, 1, 0],
        [l31, l32, 1]]

U_33 = [[u11, u12, u13],
        [0, u22, u23],
        [0, 0, u33]]

# print("L: \n", L_33)
# print("U: \n", U_33)

print("L = ")
matrix.matrix_print(L_33)
print("U = ")
matrix.matrix_print(U_33)
LU = matrix.matrix_multiplication(L_33, U_33)
print("LU = ")
matrix.matrix_print(LU)


# A_a = numpy.array([[a11, a12, a13], [a21, a22, a23], [a31, a32, a33]])
# A_m = numpy.mat("a11, a12, a13; a21, a22, a23; a31, a32, a33")
# print("原矩阵为：\n", A_a)


#【Crout分解法】
# L是单位下三角阵，U是上三角阵



# Cholesky分解法（平方根法）